package com.example.service;

import java.util.List;
//import org.neo4j.cypher.internal.compiler.v2_1.perty.docbuilders.toStringDocBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.example.Mapper.Xs_ddDao;
import com.example.pojo.Xs_dd;
import com.example.pojo.Xs_ddPage;
import com.example.pojo.Xs_ddx;

@Service
public class Xs_ddBiz {
   @Autowired
   private Xs_ddDao xs_dddao;
   
	//新增订单主表
   @Transactional
   public void savedd(Xs_dd xsdd){

	this.xs_dddao.savedd(xsdd);
	 for (Xs_ddx dd : xsdd.getXs_ddx()) {
		this.xs_dddao.saveddx(dd);
	}
		
	};
	 //审核
	@Transactional
	public void shenhe(String Billno){
		System.out.println(Billno+"service层");
	    this.xs_dddao.shenhe(Billno);
	   
	};
	
	
	//查询主详
	public   Xs_ddPage selXs_dd(int size){
		List<Xs_dd> d=this.xs_dddao.selxsdd(size);
		for (Xs_dd xs_dd : d) {
			xs_dd.setXs_ddx(this.xs_dddao.selxsddx(xs_dd.getBillno()));
		}
		Xs_ddPage pp=new Xs_ddPage();
		int count=this.xs_dddao.count(size);
		pp.setList(d);
		pp.setPage(size);
		pp.setPagesize(1);
		pp.setTotalsize(count);
		
		return pp;
	}
	
	//修改单况
	public void updatexsddx(String billno){
		
		this.xs_dddao.updatexsddx(billno);
	};
	
   public void updatexsx(String billno){
		
		this.xs_dddao.updatexsx(billno);
	};
	
	
	
	//反审核
	public void shenhe2(String billno){
		 this.xs_dddao.shenhe2(billno);
		
	};
	
	//历史交易查询
	public List<Xs_dd> queryxsdd(){
		List<Xs_dd> list=this.xs_dddao.lsjycx();
		 for (Xs_dd xs_bj : list) {
			 xs_bj.setTrantype("销售报价单");
		}
		return list;
	}
	
	
	//转销售报价单
	public List<Xs_dd> queryxsbjinfo(){
		 List<Xs_dd> list=this.xs_dddao.queryxsbjinfo();
		 System.out.println(list+"service层");
		 for (Xs_dd xs_bj : list) {
			 xs_bj.setTrantype("销售报价单");
		}
		 return list;
	};
	
    //修改
	@Transactional
	public void upxsdd(Xs_dd billno){
		Xs_dd dd=this.xs_dddao.selectxsdd(billno.getBillno());
		System.out.println(dd+"dd加service");
		if(dd!=null||!dd.equals("")){
			
			this.xs_dddao.delXs_ddx(billno.getBillno());
			this.xs_dddao.delXs_dd(billno.getBillno());
			this.xs_dddao.savedd(dd);
		}
		
		for (Xs_ddx d : dd.getXs_ddx()) {
				this.xs_dddao.saveddx(d);
			}
		
	}
	
	
	//删除主表
	@Transactional
	public void delXs_ddx(String Billno){
		this.xs_dddao.delXs_ddx(Billno);
		this.xs_dddao.delXs_dd(Billno);
	};
	
	
 
}
